﻿package  src.game {
	import src.Star;
	import src.Const;
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.display.MovieClip;

	public class PointsHolder extends Holder {
		private var currentStar:MovieClip;
		private var numberOfStars:int;
		
		public function PointsHolder(display:DisplayObjectContainer) {
			super(display);
		}
	
		public function init():void {
			var s:MovieClip = new Star();
			holder.addChild(s);
			s.stop();
			s.y = s.height / 2;
			if (currentStar == null) {
				s.x = s.width / 2 + s.width / 6;
			}
			else
				s.x = currentStar.x + s.width + s.width / 6;
			currentStar = s;
			numberOfStars++;
		}
		
		public function addPoints():void {
			var currentFrame:int = currentStar.currentFrame + 1;
			if (currentFrame > currentStar.totalFrames && numberOfStars < Const.MAX_STARS)
				init();
			else
				currentStar.gotoAndStop(currentFrame);
		}
		
		public function restartPoints():void {
			numberOfStars == 0;
			for (var i:int = holder.numChildren - 1; i>= 0; i--)
				holder.removeChildAt(i);
			currentStar = null;
			
			init();
		}
 	}
	
}
